
var deltaX = 0;
var temp = 0;
var Paddle = function () {
  //使用wx.createContext获取绘图上下文context
  var context = wx.createCanvasContext("firstCanvas");

  var o = {
    image: "/image/paddle.png",
    x: 100,
    y: 250,
    w: 150,
    h: 25,
    speed: 5,
  }

  o.draw = function () {
    context.drawImage(o.image, o.x, o.y, o.w, o.h);
    context.draw()
  }
  return o;
}
var paddle = Paddle();

Page({
  canvasIdErrorCallback: function (e) {
    console.error(e.detail.errMsg);
  },
  touchStart: function (e) {
    deltaX = e.changedTouches[0].x
  },
  touchMove:function(e){
    var x = e.changedTouches[0].x - deltaX
    if (x != temp){
      paddle.x += x/10;
      paddle.draw()
      console.log("m:" + x)
    }
    temp = x;
  },
  touchEnd: function (e) {
    var x = e.changedTouches[0].x - deltaX
    paddle.x += x;
    paddle.draw()
    console.log("e:" + x)
  },
  onReady: function (e) {
    paddle.draw()
  }
});